package com.minisoft.pool;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.Page;
import cn.hutool.db.PageResult;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

/**
 * @author JueSu
 * @description: TODO
 * @date 2023/7/4 17:09
 */
@Slf4j
public class QueryPreMobile {

    public static String DB_CENTER = "center-pro";

    public static void main1(String[] args) throws SQLException {
        ExcelReader reader = ExcelUtil.getReader("D:\\temp\\changshamobile.xls");
        List<List<Object>> rows = reader.read(0);
        String sql = "select cm.mobile from customer_opportunity co \n" +
                "join customer_mobile cm on cm.customer_opportunity_id = co.customer_opportunity_id and cm.deleted = 0 and cm.sort = 0 \n" +
                "where co.opportunity_state = 2 and co.visit_last_date > '2019-01-01' and ";
        Set mobiles = new HashSet();
        for (List<Object> row : rows) {
            String or = row.stream().map(item -> StrUtil.format("cm.mobile like '{}%'", item)).collect(Collectors.joining(" or "));
            String sql1 = sql + or;
            List<Entity> query = Db.use(DB_CENTER).query(sql1);
            for (Entity entity : query) {
                mobiles.add(entity.get("mobile"));
            }
        }
        System.out.println(mobiles.size());
        FileUtil.writeUtf8Lines(mobiles,"d:/temp/changshamobile.txt");
    }

    public static void main2(String[] args) {
        ExcelWriter writer = ExcelUtil.getWriter("d:/temp/_身份证是43开头及成交地址包含湖南及指定前缀__202310071106.xlsx");
        writer.setSheet(0);
        int rowCount = writer.getRowCount();
        for (int i = 1;i < rowCount;i++) {
            long value = (long) writer.getCell(0, i).getNumericCellValue();
            String s = String.valueOf(value);
            writer.writeCellValue(1,i, DigestUtil.md5Hex(s));
        }
        writer.flush();
    }

    public static void main(String[] args) {
        ExcelWriter writer = ExcelUtil.getWriter("d:/temp/daasResult-1707873516369.xlsx");
        writer.setSheet(0);
        int rowCount = writer.getRowCount();
        for (int i = 1;i < rowCount;i++) {
            String s = null;
            try {
                long value = (long) writer.getCell(0, i).getNumericCellValue();
                s = String.valueOf(value);
            } catch (Exception e) {
                s = writer.getCell(0, i).getStringCellValue();
                System.out.println(e.getMessage()+"/" + i);
            }
            writer.writeCellValue(1,i, DigestUtil.md5Hex(s));
        }
        writer.flush();
    }



}
